In [ ]:
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import random
plt.style.use('ggplot')
Load fake data into a pandas DataFrame. Use the dt column an the index for the DataFrame
In [ ]:
raw_data = {'dt': ['2017-01-15 00:06:08',
'2017-01-15 01:09:08',
'2017-01-16 02:07:08',
'2017-01-16 02:07:09',
'2017-01-16 03:04:08',
'2017-01-16 03:04:09',
'2017-01-15 01:06:08'],
'type': ['VOLT',
'VOLT',
'PUMP',
'PUMP',
'PUMP',
'PUMP',
'VOLT'],
'value': [22.4,
34.3,
0.,
1.,
1.,
0.,
34.3]}
df = pd.DataFrame(raw_data, index=raw_data['dt'], columns = ['type', 'value'])
df
Convert the type column to a category (similar to factor in R)
In [ ]:
df.type = df.type.astype('category')
Plot the noise readings as a point plot
In [ ]:
plt.figure()
df[df.type=='VOLT'].plot(rot=90,title='NoiseReading',style='o')
plt.show()
plt.savefig('DataFramePlotting01.png')
Plot the pump state changes as a line plot.
In [ ]:
plt.figure()
df[df.type=='PUMP'].plot(rot=90,title='Pump State',style='-')
plt.show()
plt.savefig('DataFramePlotting02.png')
In [ ]:
group = df.groupby(['type'])
group.plot()
plt.show()
plt.savefig('DataFramePlotting03.png')
In [ ]:
fig, axs = plt.subplots(1,2,sharex=False)
group.get_group("PUMP").plot(ax=axs[0], y='value', rot=90,title='Pump State',style='-')
group.get_group("VOLT").plot(ax=axs[1], y='value', rot=90,title='Volt Noise',style='.')
plt.show()
plt.savefig('DataFramePlotting04.png')